package com.mhfelipe.sandbox.prevayler.manager;

import com.mhfelipe.sandbox.prevayler.context.PrevaylerContext;
import com.mhfelipe.sandbox.prevayler.prevalence.Empresa;
import com.mhfelipe.sandbox.prevayler.prevalence.entity.Funcionario;
import org.prevayler.Prevayler;
import org.prevayler.Transaction;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: mhfelipe
 * Date: 2/3/12
 * Time: 9:48 AM
 * To change this template use File | Settings | File Templates.
 */
public class FuncionarioManager implements Serializable {

    private final Prevayler prevayler = PrevaylerContext.getInstance();

    public void persist(final Funcionario funcionario) {
        prevayler.execute(new Transaction() {
            public void executeOn(Object prevalentSystem, Date executionTime) {
                Empresa empresa = (Empresa) prevalentSystem;
                empresa.getFuncionarioList().add(funcionario);
            }
        });
    }

    public List<Funcionario> list() {
        return ((Empresa)prevayler.prevalentSystem()).getFuncionarioList();
    }

}
